package com.example.myhuangye.call;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lc on 2017/4/18.
 */

public class SelectTel {

    public static List<Contacts> select(Context context){
        List<Contacts> lists=new ArrayList<>();
        Uri uri=Uri.parse("content://com.android.contacts/raw_contacts");
        Uri data=Uri.parse("content://com.android.contacts/data");
        Cursor cursor= context.getContentResolver().query(uri,new String[]{"contact_id"},null,null,null);//获取内容提供者的手机联系人
        Contacts contacts;
        while (cursor.moveToNext()){
            contacts=new Contacts();
            contacts._id=cursor.getInt(0);
            Cursor cursor1=context.getContentResolver().query(data,new String[]{"mimetype","data1"},"contact_id=?",new String[]{String.valueOf(contacts._id)},null);
            while (cursor1.moveToNext()){
                if("vnd.android.cursor.item/phone_v2".equals(cursor1.getString(0))){
                    contacts._tel=cursor1.getString(1);
                }else if("vnd.android.cursor.item/name".equals(cursor1.getString(0))) {
                    contacts._name=cursor1.getString(1);
                }
            }
            lists.add(contacts);
        }
        return lists;
    }
}
